/*
 * subject_3.cpp
 *
 *  Created on: 2011-2-23
 *      Author: Aeolus
 */
#include <vector>
#include <string>
#include <sstream>
#include "LinearTimeChoose.cpp"

using namespace std;
class GetMainMember
{
public :
	template<class Type>
	string getMainMember(vector<Type> data)
	{
		LinearTimeChoose ltc;
		string str = "";
		stringstream ss;
		int search_location = (data.size()+1)/2;
		Type median = ltc.randomizeSelect(data,0,data.size(),search_location);
		int occur_number = 0;
		for(typename vector<Type>::size_type i=0; i != data.size() ; i++)
		{
			if(data[i] == median)
				occur_number ++;
		}
		if(occur_number > data.size()/2)
			{
				ss<<median;
				ss>>str;
				return str;
			}
		else
			return "null";
	}
};

